package com.bdsy.common.tag;

import javax.servlet.DispatcherType;
import javax.servlet.http.HttpServletRequest;

import org.sitemesh.webapp.contentfilter.Selector;

public class DecorateErrorPageSelector implements Selector{
	private final Selector oldSelector;

    public DecorateErrorPageSelector(Selector oldSelector) {
        super();
        this.oldSelector = oldSelector;
    }

    @Override
    public boolean shouldBufferForRequest(HttpServletRequest request) {
        if(request.getDispatcherType() == DispatcherType.ERROR) {
            request.removeAttribute("org.sitemesh.webapp.contentfilter.BasicSelector.APPLIED_ONCE");
    		//return false;
        }
        //}else{
        	return oldSelector.shouldBufferForRequest(request);
        //}
    }

    @Override
    public String excludePatternInUse(HttpServletRequest request) {
        return oldSelector.excludePatternInUse(request);
    }

    @Override
    public boolean shouldAbortBufferingForHttpStatusCode(int statusCode) {
        return oldSelector.shouldAbortBufferingForHttpStatusCode(statusCode);
    }

    @Override
    public boolean shouldBufferForContentType(String contentType, String mimeType, String encoding) {
        return oldSelector.shouldBufferForContentType(contentType, mimeType, "utf-8");
    }
}
